<!DOCTYPE HTML>
<html>
<head>
<#include "../common/_meta.html">
    <title>推送属性到整个集群</title>
</head>
<body>
<article class="cl pd-20">
    <form class="form form-horizontal" name="form-edit-cluster-attribute" id="form-edit-cluster-attribute">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">集群：</label>
            <div class="formControls col-xs-8 col-sm-9">${cluster!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">实例：</label>
            <div class="formControls col-xs-8 col-sm-9">全部</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">属性：</label>
            <div class="formControls col-xs-8 col-sm-9">${attribute!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>修改为：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" placeholder="不修改请留空" name="newattribute" id="newattribute">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存并推送&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<#include "../common/_footer.html">

<script type="text/javascript">
    $(function(){
        $("#form-edit-cluster-attribute").validate({
            rules:{
                newattribute:{
                    required:true
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(){
                invokeAll();
            }
        });
    });

    function invokeAll() {
        var clusterValue = "${cluster!''}";
        var attrName = "${attribute!''}";
        var attrAllValue = $("#newattribute").val();
        layer.confirm("确定要全部推送数据吗", {icon: 3, title:'提示'}, function (flag) {
            var index = layer.load(2);
            if (flag) {
                $.ajax({
                    type: "POST",
                    url: "${base}/resource_manage/push_all_attribute",
                    data: {"cluster": clusterValue, "attribute": attrName, "attributeValue": attrAllValue, "sendType": 2},
                    dataType: "json",
                    success: function (result) {
                        layer.close(index);
                        if (result.code === 0) {
                            layer.msg("推送成功", {icon:6,time:2000}, function () {layer_close();});
                        } else if (result.code === 1) {
                            layer.alert("部分推送成功", {icon:6,time:2000}, function () {layer_close();});
                        } else {
                            layer.msg("推送失败", {icon:5,time:2000}, function () {layer_close();});
                        }
                    },
                    error: function (result) {
                        layer.close(index);
                        layer.msg("错误", {icon:5,time:2000}, function () {layer_close();});
                    }
                });
            }
        }, function () {
        });
    }
</script>
</body>
</html>